package com.xwj.service.holder;

import com.xwj.entity.PassWordEntity;
import com.xwj.service.Impl.RegisterUserServiceImpl;
import org.apache.shiro.crypto.hash.Md5Hash;

public class RaRegisterUserHolder {

    private static RegisterUserServiceImpl registerUserService = RegisterUserServiceImpl.getInstance();

    /**
     * 校验密码
     *
     * @param id
     * @param pwd
     * @return
     */
    public static boolean checkPassWord(String id, String pwd) {
        PassWordEntity passWordEntity = registerUserService.getUserPassWord(id);
        if (passWordEntity.getPassword().equals(new Md5Hash(pwd, passWordEntity.getSalt()).toString()))
            return true;
        return false;
    }

    /**
     * 是否有该用户
     *
     * @param userId
     * @return
     */
    public static boolean hasUser(String userId) {
        if (registerUserService.findUserById(userId) == null)
            return false;
        return true;
    }
}
